package org.example.struct.array2;

/**
 * @author liyishan
 * @date 2023/11/8 09:40
 * @apiNote
 */

public class Test01052MaxSatisfied {

    public static void main(String[] args) {
        int[] customers = {1,0,1,2,1,1,7,5};
        int[] grumpy = {0,1,0,1,0,1,0,1};
        int count = test(customers, grumpy, 3);
        System.out.println(count);
    }

    public static int test(int[] customers, int[] grumpy, int minutes) {
        int total = 0;
        int n = customers.length;
        for(int i = 0; i < n; i++){
            if(grumpy[i] == 0){
                total += customers[i];
            }
        }
        for(int i = 0; i < minutes; i++){
            total += customers[i]*grumpy[i];
        }
        int maxIncrease = total;
        for(int i = minutes; i < n; i++){
            total += customers[i]*grumpy[i] - customers[i-minutes]*grumpy[i-minutes];
            maxIncrease = Math.max(maxIncrease, total);
        }
        return maxIncrease;
    }
}
